const http = require("http");
const fs=require('fs')
const server = http.createServer((req, res) => {
  res.setHeader("content-type", "text/html;charset=utf-8");
  if (req.url !== "/favicon.ico") {
    let str = req.url;

    let getArgu = (str) => {
      var arr = str.split("?")[1].split("&");
      console.log(arr);
      var obj = {};
      arr.forEach((item) => {
        var result = item.split("=");
        obj[result[0]] = result[1];
      });
    //   console.log(obj); //将请求参数转换成对象
    var Obj=JSON.stringify(obj)//将对象转换成json格式
    fs.writeFile('./data.json',Obj,err=>{
        console.log(err)
    })
      // console.log(Obj)  
    };
    getArgu(str);
  }
  res.write("hello");
  res.end();
});

server.listen(8090);
